package cn.aicnn.chatssespringboot.controller;

import cn.aicnn.chatssespringboot.common.CommonResponse;
import cn.aicnn.chatssespringboot.dto.Dialog;
import cn.aicnn.chatssespringboot.dto.NameRequest;
import cn.aicnn.chatssespringboot.service.ChatService;
import cn.aicnn.chatssespringboot.vo.DialogVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class DialogController {
    @Autowired
    ChatService chatService;
    @PatchMapping("/api/chat/{chatid}/name")
    CommonResponse<Object> changeTitle(@PathVariable int chatid, @RequestBody NameRequest request){
        String name = request.getName();
        return chatService.changeTitle(chatid, name);
    }

    @DeleteMapping("/api/chat/{chatid}")
    CommonResponse<Object> deleteChat(@PathVariable int chatid){
        return chatService.deleteChat(chatid);
    }

    @GetMapping("/api/chat/{chatid}/dialog")
    CommonResponse<List<Dialog>> getDialog(@PathVariable int chatid){
        return chatService.getDialog(chatid);
    }

    @GetMapping("/api/user/{username}/chat")
    CommonResponse<List<DialogVO>> getChatList(@PathVariable String username){
        return chatService.getChatList(username);
    }
}
